package rpg.engine.client;

import java.util.List;

import rpg.client.GameEngine;
import rpg.client.Instruction;
import rpg.client.model.Actor;
import rpg.client.model.ActorInfo;
import rpg.client.model.ClientMap;
import rpg.client.model.Dialog;
import rpg.client.model.GameEvent;
import rpg.engine.client.cache.WorldCacheFactory;
import rpg.engine.model.DialogInfo;
import rpg.engine.model.World;
import rpg.util.Objects;

public class GameEngineFacade implements GameEngine {
    private final WorldCacheApi worldCache;
    private final ClientEngine engine;

    public GameEngineFacade(World world) {
        super();
        worldCache = WorldCacheFactory.newInstance(world);
        engine = new ClientEngine(worldCache);
    }

    @Override
    public List<GameEvent> addPlayer(Actor player) {
        Objects.requireNonNull(player, "ClientEngine.player");
        return engine.addPlayer(player);
    }

    @Override
    public ActorInfo character(String playerID) {
        return engine.getCharacter(playerID);
    }

    @Override
    public Actor getActor(String actorId) {
        return worldCache.getNpc(actorId).getActor();
    }

    @Override
    public Dialog getDialog(String storyID, String chatID) {
        DialogInfo di = worldCache.getDialog(storyID, chatID);
        return di.getDialog();
    }

    @Override
    public ClientMap getGameMap(String mapID) {
        return worldCache.getGameMap(mapID);
    }

    @Override
    public List<Instruction> getPossibleInstructions(String playerID) {
        return engine.getPossibleInstructions(playerID);
    }

    @Override
    public List<GameEvent> instruction(Instruction instruction) {
        return engine.instruction(instruction);
    }

    @Override
    public Actor registerPlayer(Actor.Builder ab) {
        return worldCache.registerPlayer(ab);
    }
}
